namespace ACRSAP.Administration.Projects.UserControls
{
    using ASPNET.StarterKit.IssueTracker.BusinessLogicLayer;
    using ASPNET.StarterKit.IssueTracker.UserInterfaceLayer;
    using System;
    using System.Collections;
    using System.Diagnostics;
    using System.Runtime.CompilerServices;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class ProjectMembers : UserControl, IEditProjectControl
    {
        [AccessedThroughProperty("btnAdd")]
        private Button _btnAdd;
        [AccessedThroughProperty("btnRemove")]
        private Button _btnRemove;
        [AccessedThroughProperty("lstAllUsers")]
        private ListBox _lstAllUsers;
        [AccessedThroughProperty("lstSelectedUsers")]
        private ListBox _lstSelectedUsers;
        private int _ProjectId;
        private object designerPlaceholderDeclaration;

        public ProjectMembers()
        {
            base.Init += new EventHandler(this.Page_Init);
            this._ProjectId = -1;
        }

        public void AddUser(object s, EventArgs e)
        {
            if ((this.lstAllUsers.SelectedIndex > -1) && Project.AddUserToProject(int.Parse(this.lstAllUsers.SelectedValue), this.ProjectId))
            {
                this.lstSelectedUsers.SelectedIndex = -1;
                this.lstSelectedUsers.Items.Add(this.lstAllUsers.SelectedItem);
                this.lstAllUsers.Items.Remove(this.lstAllUsers.SelectedItem);
            }
        }

        public void Initialize()
        {
            IEnumerator _Vb_t_ref_0 = null;
            this.lstAllUsers.Items.Clear();
            this.lstSelectedUsers.Items.Clear();
            this.lstAllUsers.DataSource = ITUser.GetAllUsers();
            this.lstAllUsers.DataTextField = "DisplayName";
            this.lstAllUsers.DataValueField = "Id";
            this.lstAllUsers.DataBind();
            ITUserCollection projectUsers = ITUser.GetUsersByProjectId(this.ProjectId);
            try
            {
                _Vb_t_ref_0 = projectUsers.GetEnumerator();
                while (_Vb_t_ref_0.MoveNext())
                {
                    ITUser currentUser = (ITUser)_Vb_t_ref_0.Current;
                    ListItem matchItem = this.lstAllUsers.Items.FindByValue(currentUser.Id.ToString());
                    if (matchItem != null)
                    {
                        this.lstSelectedUsers.Items.Add(matchItem);
                        this.lstAllUsers.Items.Remove(matchItem);
                    }
                }
            }
            finally
            {
                if (_Vb_t_ref_0 is IDisposable)
                {
                    ((IDisposable)_Vb_t_ref_0).Dispose();
                }
            }
        }

        [DebuggerStepThrough]
        private void InitializeComponent()
        {
        }

        private void Page_Init(object sender, EventArgs e)
        {
            this.InitializeComponent();
        }

        public void RemoveUser(object s, EventArgs e)
        {
            if ((this.lstSelectedUsers.SelectedIndex > -1) && Project.RemoveUserFromProject(int.Parse(this.lstSelectedUsers.SelectedValue), this.ProjectId))
            {
                this.lstAllUsers.SelectedIndex = -1;
                this.lstAllUsers.Items.Add(this.lstSelectedUsers.SelectedItem);
                this.lstSelectedUsers.Items.Remove(this.lstSelectedUsers.SelectedItem);
            }
        }

        public bool Update()
        {
            return true;
        }

        int ASPNET.StarterKit.IssueTracker.UserInterfaceLayer.IEditProjectControl.ProjectId
        {
            get
            {
                return this._ProjectId;
            }
            set
            {
                this._ProjectId = value;
            }
        }

        protected virtual Button btnAdd
        {
            get
            {
                return this._btnAdd;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnAdd != null)
                {
                    this._btnAdd.Click -= new EventHandler(this.AddUser);
                }
                this._btnAdd = value;
                if (this._btnAdd != null)
                {
                    this._btnAdd.Click += new EventHandler(this.AddUser);
                }
            }
        }

        protected virtual Button btnRemove
        {
            get
            {
                return this._btnRemove;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._btnRemove != null)
                {
                    this._btnRemove.Click -= new EventHandler(this.RemoveUser);
                }
                this._btnRemove = value;
                if (this._btnRemove != null)
                {
                    this._btnRemove.Click += new EventHandler(this.RemoveUser);
                }
            }
        }

        protected virtual ListBox lstAllUsers
        {
            get
            {
                return this._lstAllUsers;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lstAllUsers != null)
                {
                }
                this._lstAllUsers = value;
                if (this._lstAllUsers != null)
                {
                }
            }
        }

        protected virtual ListBox lstSelectedUsers
        {
            get
            {
                return this._lstSelectedUsers;
            }
            [MethodImpl(MethodImplOptions.Synchronized)]
            set
            {
                if (this._lstSelectedUsers != null)
                {
                }
                this._lstSelectedUsers = value;
                if (this._lstSelectedUsers != null)
                {
                }
            }
        }

        public int ProjectId
        {
            get
            {
                return this._ProjectId;
            }
            set
            {
                this._ProjectId = value;
            }
        }
    }
}

